package dao;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;

import model.DataModel;
import model.types.Patient;
import dao.interfaces.DataBase;

public class UseFilesAsDataBase implements DataBase {

	private final File dbFile = new File("patients.pdb");

	@Override
	public void connect() {
	}

	@Override
	public void disConnect() {
	}

	@Override
	public List<Patient> getData() throws IOException, ClassNotFoundException {
		FileInputStream fileInputStream = new FileInputStream(dbFile);
        ObjectInputStream ois = new ObjectInputStream(fileInputStream);
		return (List<Patient>)ois.readObject();
	}

	@Override
	public void saveData(List<Patient> patients) throws IOException {
		FileOutputStream fileOutputStream = new FileOutputStream(dbFile);
		ObjectOutputStream oos = new ObjectOutputStream(fileOutputStream);
		oos.writeObject(patients);
	}
}
